"""
A class to exercise the JT core functions.
"""
import itk
import vtk
import JT2 as JT
import Calibration
from numpy import array

def Test():
    """
    Test the volume rendering implemented in JT
    """
    inputVolFileName = 'C:/Users/bryan/bryan-code/2D3D/vert1/CT/ucharCTv1r1.mha'
    maskFileName1 = 'C:/Users/bryan/bryan-code/2D3D/vert1/CT/ucharCTv1r1b1VOI.mha'
    maskFileName2 = 'C:/Users/bryan/bryan-code/2D3D/vert1/CT/ucharCTv1r1b2VOI.mha'
    maskFileName3 = 'C:/Users/bryan/bryan-code/2D3D/vert1/CT/ucharCTv1r1b3VOI.mha'
    staFile = 'C:/Users/bryan/bryan-code/2D3D/vert1/CT/ucharCTv1r1.sta'
    calFile = 'C:/Users/bryan/bryan-code/trunk/TestData/ext_cal1.txt'

#===============================================================================
#    Generate Lateral Projection
#===============================================================================
    xraycam = JT.XRayCamera()
    drr = JT.DRR()
    
    drr.SetXRayCamera(xraycam)
    drr.SetBlackOnWhiteImage()

#===============================================================================
#    Calibration
#===============================================================================
    cal = Calibration.ExternalCalibration()
    cal.LoadConsolidatedCalibration(calFile)
    cal.LoadStaFile(staFile)
    
    xraycam.SetExternalCalibration(cal)
    # Setup volume 1
    volume1 = JT.IsoActor()
    volume1.SetVolumeFilename(inputVolFileName)
    volume1.SetImageMask(maskFileName1)
    volume1.CreateIsoSurface()
    volume1.SetOriginalTransform(cal._VolumeT)
    volume1.SetBodyCenter((3.906, -24.738, -12.586))
   
#    # Setup Volume 2
    volume2 = JT.IsoActor()
    volume2.SetVolumeFilename(inputVolFileName)
    volume2.SetImageMask(maskFileName2)
    volume2.CreateIsoSurface()
    volume2.SetOriginalTransform(cal._VolumeT)
    volume2.SetBodyCenter((3.906, 2.17, -7.378))
    
#    # Setup Volume 3
    volume3 = JT.IsoActor()
    volume3.SetVolumeFilename(inputVolFileName)
    volume3.SetImageMask(maskFileName3)
    volume3.CreateIsoSurface()
    volume3.SetOriginalTransform(cal._VolumeT)
    volume3.SetBodyCenter((7.378, 27.342, -6.51))
    
    
    drr.AddVolume(volume1)
    drr.AddVolume(volume2)
    drr.AddVolume(volume3)
    
    print "# volumes: ", len(drr._volume_list)


    for i in range(20):
        #pose = (0,0,0,i*3.1415/180,0,0)
        volume1.RotateX(i*3.14/180)
        drr.Render()
        print "Rotate X: ", i
    
    print "Done!"
    drr.UseVTKInteractionStyle()
    drr.StartInteraction()
#    drr.SaveGeneratedImage('C:/Users/bryan/bryan-code/trunk/Images/CurrentDRR.png')


if __name__ == "__main__":
    Test()